#!/bin/bash

declare -a check_status

check_status=($(/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg |grep Total |awk -F: '{print $2}'| awk 'gsub(/^ *| *$/,"")'))

echo ${check_status[0]}
echo ${check_status[1]}

if [ "${check_status[0]}" = "0" -a "${check_status[1]}" = "0" ];then  
  echo "Nagios pre check success, now will restart the nagios server..."
  service nagios restart
else
  echo "Nagios pre check failed, please recheck your configuration, and the server will not be restarted!";
fi
